import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import elib.Klient;
import elib.Osoba;

@WebServlet("/DeleteReservationServlet")
public class DeleteReservationServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public DeleteReservationServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		HttpSession session = request.getSession();
		String id = request.getParameter("id");
		String rdy = request.getParameter("rdy");
		if(id!=null && id.matches("\\d+") && session!=null) {
			Osoba osoba = (Osoba) session.getAttribute("osoba");
			if(osoba != null && osoba instanceof Klient) {
				if(rdy!=null && rdy.equals("Tak"))
					((Klient) osoba).anulujRezerwacje(Integer.parseInt(id), 1);
				else
					((Klient) osoba).anulujRezerwacje(Integer.parseInt(id), 0);
				response.sendRedirect("ShowReservationServlet");
			} else
				response.sendRedirect("index.jsp");
		} else
			response.sendRedirect("index.jsp");
		out.close();
	}
}